package org.classg.statistics.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.classg.statistics.service.StatisticsDailyService;
import org.classg.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-06-19
 */
@Api(description = "统计日志管理")
@RestController
@RequestMapping("/statisticsservice")
@CrossOrigin
public class StatisticsDailyController {

    @Autowired
    private StatisticsDailyService statisticsDailyService;

    @ApiOperation("根据天数统计人数，生成统计数据")
    @PutMapping("/insertStaByDay/{day}")
    public R insertStaByDay(@ApiParam(name = "day", value = "天数", required = true) @PathVariable String day) {
        statisticsDailyService.insertStaByDay(day);
        return R.ok();
    }

    @ApiOperation("图表显示，返回2部分数据，日期json数组和数量json数组")
    @GetMapping("/queryStaToJsonArray/{type}/{begin}/{end}")
    public R queryStaToJsonArray(@ApiParam(name = "type", value = "返回类型", required = true) @PathVariable String type,
                            @ApiParam(name = "begin", value = "开始时间", required = true) @PathVariable String begin,
                            @ApiParam(name = "end", value = "结束时间", required = true) @PathVariable String end) {
        Map<String, Object> map = statisticsDailyService.queryStaToJsonArray(type, begin, end);
        return R.ok().data(map);
    }
}

